# 有语的第一个项目实践，外星人大战项目
# 第六章，外星人绘制
# 22/10/2
import pygame
from pygame.sprite import Sprite


class Alien(Sprite):

    def __init__(self, ai_game):
        super().__init__()
        self.screen = ai_game.screen
        self.screen_rect = ai_game.screen.get_rect()
        self.settings = ai_game.settings

        self.image = pygame.image.load("image/外星人.bmp")
        self.rect = self.image.get_rect()

        # self.rect.topleft = self.screen_rect.topleft

        # 将外星人放置在左上角位置
        self.rect.x = self.rect.width
        self.rect.y = self.rect.height

        # 储存外星人的精确位置
        self.x = float(self.rect.x)

    def update(self):
        """左右移动外星人"""
        self.x += (self.settings.alien_speed * self.settings.fleet_direction)
        self.rect.x = self.x

    def check_edges(self):
        """检测外星人的位置"""
        screen_rect = self.screen.get_rect()
        if self.rect.right >= screen_rect.right or self.rect.left <= 0:
            return True
